﻿/**
 * @version 3 11 February 2013
 * @author Myhaylo Kotsyuruba
 */

public class Test {
    private String name;
    private Question[] questions;

    public Test(String name, Question[] questions) {
        this.name = name;
        this.questions = questions;
    } 

    @Override
    public String toString() {
        return name;
    }

    @Override
    public Test clone() {
        Question[] newQuestions = new Question[questions.length];
        for (int index = 0; index < questions.length; index++) {
            newQuestions[index] = questions[index].clone();
        }
        return new Test(name, newQuestions);
    }
    
    public String toStringQuestion(int index) {
        String numberString = String.format("%nQuestion %d: ", (index + 1));
        String textQuestions = numberString.concat(questions[index].toString());
        return textQuestions;
    }
    
    public AnswerMap convertsUserAnswer(int indexQestions, String userAnswer) {
        AnswerMap userAnswerMap = questions[indexQestions]
                .convertsUserAnswer(userAnswer);
        return userAnswerMap;
    }

    public AnswerMap[] getCorrectAnswers() {
        AnswerMap[] answerMap = new AnswerMap[questions.length];
        for (int index = 0; index < questions.length; index++) {
            answerMap[index] = questions[index].getCorrectAnswerMap();
            answerMap[index].setScore(questions[index].getScore());
        }
        return answerMap;
    }
    
    public int getQuantityQuestions() {
        return questions.length;
    }
    
    public int getQuestionScore(int index) {
        return questions[index].getScore();
    }
}

